<template>
  <div class="login-container">
    <el-form class="login-form" :model="loginForm" :rules="loginrule">
      <div class="title-container">
        <h3 class="title">登录</h3>
      </div>

      <el-form-item prop="username">
        <el-input
          placeholder="username"
          name="username"
          type="text"
          v-model="state.loginForm.username"
        />
      </el-form-item>

      <el-form-item prop="password">
        <el-input
          placeholder="password"
          name="password"
          type="password"
          v-model="state.loginForm.password"
        />
      </el-form-item>

      <el-button
        type="primary"
        style="width: 100%; margin-bottom: 30px"
        :loading="loading"
        @click="handleLogin"
        >登录</el-button
      >

      <!-- <div class="tips" v-html="$t('msg.login.desc')"></div> -->
    </el-form>
  </div>
</template>

<script setup>
import { ref, toRefs, reactive } from "vue";
import { useStore } from "vuex";
import { ElMessageBox, ElMessage } from "element-plus";
// import {store} from "store"
import { useRouter } from "vue-router";
import { getLogin } from "@/http/login.js";
import md5 from "md5"; //引入md5加密

/**
 * 数据
 */
const state = reactive({
  /**
   * 登录需要的数据dddddd
   */
  loginForm: {
    username: "super-admin",
    password: "123456",
  },
  /**
   * 登录表单验证规则
   */
  loginrule: {
    username: [{ required: true, trigger: "blur" }],
    password: [{ required: true, trigger: "blur" }],
  },
});


// 引入 vuex
const store = useStore();
//引入路由
const router = useRouter();

let handleLogin = async () => {
  const { username, password } = state.loginForm; // 结构登录数据把username, password结构出来
  const res = await getLogin({
    password: md5(password), //password 要进行md5 加密 md5()
    username: username,
  });
  console.log(res, "登录");
  if (res.success === true) {
    store.commit("settoken", res.data.token);
    router.push({ name: "profile" });
    ElMessage.success({
      duration: 1000,
      message: res.data.message,
    });
  }
};
</script>

<style lang="scss" scoped>
.login-container {
  min-height: 100%;
  width: 100%;
  background-color: #2d3a4b;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;

    ::v-deep .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }

    ::v-deep .el-input {
      height: 47px;
      width: 100%;

      input {
        height: 100%;
        width: 100%;
        background: transparent;
        border: 0px;
        border-radius: 0px;
        color: rgb(153, 151, 151);
        caret-color: rgb(126, 122, 122);
      }
    }
  }

  .tips {
    font-size: 16px;
    line-height: 28px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    color: #889aa4;
    vertical-align: middle;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: #eee;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }

    ::v-deep .lang-select {
      position: absolute;
      top: 4px;
      right: 0;
      background-color: white;
      font-size: 22px;
      padding: 4px;
      border-radius: 4px;
      cursor: pointer;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: #889aa4;
    cursor: pointer;
    user-select: none;
  }
}
</style>
